<template>
  <el-dialog
    title="更多配置"
    :visible.sync="isshow"
    width="500px"
  >
    <div class="dialogContent">
      <div class="item">
        <div class="item_content">
          <div>
            <el-form :model="form" ref="form" :rules="rules">
              <el-form-item label="可分配容量" label-width="130px" prop="nameList">
                <div>{{ form.total }}GB</div>
              </el-form-item>
              <el-form-item label="默认新增容量" label-width="130px" prop="defaultGroupStorageSize" required>
                <el-input-number v-model="form.defaultGroupStorageSize" :min="0"></el-input-number>
                GB
                <div class="errorTip" v-if="form.defaultGroupStorageSize>form.total">超出可分配容量，请重新分配</div>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
    <el-button @click="isshow = false">取 消</el-button>
    <el-button type="primary" @click="confirm">确 定</el-button>
  </span>
  </el-dialog>
</template>
<script>
import { editDefaultGroupStorageSize } from '@/api/library/libraryStorage'
import { getSchoolconfigInfo } from '@/api/library/librarySet'

export default {
  name: 'defaultdeploy',
  data() {
    return {
      isshow: false,
      form: {
        defaultGroupStorageSize: 400,
        total: 400
      },
      rules: {
        defaultGroupStorageSize: [
          { required: true, message: '请设置默认新增容量', trigger: 'blur' }
        ]
      },
      storageId: ''

    }

  },
  methods: {
    show() {
      this.isshow = true
      this.getSchoolInfo()
    },
    // 获取学校配置信息
    async getSchoolInfo() {
      let res = await getSchoolconfigInfo({ schoolId: this.$store.getters.schoolId })
      if (res.code == 200) {
        this.form.defaultGroupStorageSize = res.data.defaultGroupStorageSize
        this.storageId = res.data.storageId
        this.form.total = res.data.remainSize
      }
    },
    async confirm() {
      this.$refs['form'].validate(async(valid) => {
        if (valid && this.form.defaultGroupStorageSize > this.form.total) {
          return
        }
        let res = await editDefaultGroupStorageSize({
          storageId: this.storageId,
          defaultGroupStorageSize: this.form.defaultGroupStorageSize
        })
        if (res.code == 200) {
          this.$message.success('修改成功')
          this.isshow = false
        } else {
          this.$message.error(res.msg)
        }
      })

    }
  }
}

</script>


<style scoped lang="scss">
.dialogContent {
  .item {
    .item_title {
      display: flex;
      align-items: center;
      margin-bottom: 20px;

      .border {
        width: 4px;
        height: 15px;
        background-color: #0b8cfc;
        margin-right: 10px;
      }

      .title {
        font-size: 14px;
        font-weight: 500;
      }
    }
  }
}

.errorTip {
  color: red;
  font-size: 12px;
}
</style>
